package com.yueka.mapper;

import com.yueka.pojo.course.Course;
import com.yueka.pojo.course.CourseQueryParam;
import com.yueka.pojo.course.CourseRecord;
import com.yueka.pojo.studentSystem.Info;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface CourseMapper {
    List<Course> list(CourseQueryParam courseQueryParam);

    void delete(Integer id);

    void insert(Course course);

    void update(Course course);

    void finishCourse(Integer courseId);
    void cancelCourse(Integer courseId);
    @Select("select * from course c, course_student cs where c.id = cs.course_id and cs.student_id = #{studentId} order by update_time desc")
    List<Course> byStudentId(Integer studentId);

    @Select("select SUM(s.total_lessons) from course s, course_student cs\n" +
            "where s.id = cs.course_id and cs.student_id = #{studentId}")
    Integer getallTotalLessons(Integer studentId);

    List<CourseRecord> openCourse(java.time.LocalDateTime start, java.time.LocalDateTime end);

    @Select("select sum(c.total_lessons) as courseSum, sum(c.finished_lessons) as courseFinishedSum from course c, course_student cs where c.id = cs.course_id and cs.student_id = #{studentId}")
    Info selectInfo(Integer studentId);

    @Select("select c.id as id, course_name, type, ic_Id, total_lessons, finished_lessons, teacher_id, duration, schedule_type, repeat_type, repeat_weekly, start_time, schedule_time, teacher_name from course c, course_student cs, teacher t where c.id = cs.course_id and c.teacher_id = t.id and cs.student_id = #{studentId};")
    List<Course> selectCourseList(Integer studentId);


    List<Course> timeRepeats(Course course);
}
